﻿using IntelligentAgriculture.Contracts.Dto.Input;
using IntelligentAgriculture.Contracts.Dto.Output;
using IntelligentAgriculture.Domain.Entity;
using IntelligentAgriculture.WebAPI.Application.Command.BreedingInfoCommand;
using IntelligentAgriculture.WebAPI.Application.Command.GermlineHistoryRecordsCommand;
using IntelligentAgriculture.WebAPI.Application.Command.StartCommand;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Yitter.IdGenerator;

namespace IntelligentAgriculture.WebAPI.Controllers
{
    /// <summary>
    /// 种母配种
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BreedingInfoController : ControllerBase
    {

        /// <summary>
        /// 中介者模式
        /// </summary>
        private readonly IMediator _mediator;
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<HistoryController> _logger;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">中介者模式</param>
        /// <param name="logger">日志</param>
        public BreedingInfoController(IMediator mediator, ILogger<HistoryController> logger)
        {
            _mediator = mediator;
            _logger = logger;
        }



        /// <summary>
        /// 种母配种信息显示查询
        /// </summary>
        /// <param name="input">输入参数</param>
        /// <returns>返回数据</returns>
        [HttpGet]
        public async Task<Results<PageOutput<BreedingInfoOutPut>>> GetBreedingInfo([FromQuery] BreedingInfoInput? input)
        {
            try
            {
                _logger.LogInformation("这是种母配种信息显示查询表");
                var list = new SelectBreedingInfoCommand(input);
                return await _mediator.Send(list);
            }
            catch (Exception ex)
            {
                _logger.LogError("这是种母配种信息显示查询发生异常" + ex.Message);
                throw;
            }
        }



        /// <summary>
        /// 逻辑删除种母配种数据
        /// </summary>
        /// <param name="command">主键id</param>
        /// <returns>受影响的行数</returns>
        /// 

        [HttpDelete]
        public async Task<Results<int>> DeleteBreedingInfo(DelBreedingInfoCommand command)
        {
            try
            {
                _logger.LogInformation("这是删除种母配种删除");


                return await _mediator.Send(command);

            }
            catch (Exception ex)
            {
                _logger.LogError("这是删除种母配种发生异常" + ex.Message);
                throw;
            }
        }

        /// <summary>
        /// 逻辑批量删除种母配种数据
        /// </summary>
        /// <param name="command">主键id</param>
        /// <returns>受影响的行数</returns>
        /// 

        [HttpPut]
        public async Task<Results<int>> DeleteRangeBreedingInfo(DelRangeBreedingInfoCommand command)
        {
            try
            {
                _logger.LogInformation("这是逻辑批量删除种母配种");


                return await _mediator.Send(command);

            }
            catch (Exception ex)
            {
                _logger.LogError("这是逻辑批量删除种母配种发生异常" + ex.Message);
                throw;
            }
        }



        /// <summary>
        /// 添加种母配种表数据
        /// </summary>
        /// <param name="input">实体</param>
        /// <returns>返回受影响的行数</returns>

        [HttpPost]
        public async Task<Results<int>> AddBreedingInfo(List<Breedinginfo> input)
        {
            try
            {
                _logger.LogInformation("这是种母配种添加");
                var command = new AddBreedingInfoCommand(input);
                return await _mediator.Send(command);

            }
            catch (Exception ex)
            {
                _logger.LogError("这是种母配种添加发生异常" + ex.Message);
                throw;
            }
        }












    }
}
